package com.probiz.estore.common.model.system.base;

import java.io.Serializable;
import java.util.Map;
import java.util.HashMap;
import com.probiz.estore.core.model.BaseObject;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;

/**
 * AppResourceRole Base Java Bean, base class for the model, mapped directly to database table
 * 
 * Avoid changing this file if not necessary, will be overwritten. 
 *
 */
public class AppResourceRoleTbl extends BaseObject implements Serializable {

	protected AppResourceRolePK appResourceRolePK = new AppResourceRolePK();
	protected com.probiz.estore.common.model.system.AppResource appResource;
	protected com.probiz.estore.common.model.system.AppRole appRole;


	/**
	 * Default Empty Constructor for class AppResourceRole
	 */
	public AppResourceRoleTbl () {
		super();
	}
	
	/**
	 * Default Key Fields Constructor for class AppResourceRole
	 */
	public AppResourceRoleTbl (
		 Integer in_roleId
		,Integer in_resourceId
        ) {
		this.setRoleId(in_roleId);
		this.setResourceId(in_resourceId);
    }

	
	public com.probiz.estore.common.model.system.AppResource getAppResource () {
		return appResource;
	}	
	
	public void setAppResource (com.probiz.estore.common.model.system.AppResource in_appResource) {
		this.appResource = in_appResource;
	}
	
	public com.probiz.estore.common.model.system.AppRole getAppRole () {
		return appRole;
	}	
	
	public void setAppRole (com.probiz.estore.common.model.system.AppRole in_appRole) {
		this.appRole = in_appRole;
		this.getAppResourceRolePK().setRoleId(appRole.getRoleId());
	}
  /**
	* @return appResourceRolePK
	*/
	public AppResourceRolePK getAppResourceRolePK() {
		return this.appResourceRolePK;
	}
	
  /**
	* @set appResourceRolePK
	*/
	public void setAppResourceRolePK(AppResourceRolePK aPrimaryKey) {
		this.appResourceRolePK = aPrimaryKey;
	}
    

	/**
	 * 	 * @return Integer
     * @hibernate.id column="roleId" type="java.lang.Integer" generator-class="native"
	 */
	public Integer getRoleId() {
		return this.getAppResourceRolePK().getRoleId();
	}
	
	/**
	 * Set the roleId
	 */	
	public void setRoleId(Integer aValue) {
	    if (aValue==null) {
	    	appRole = null;
	    } else {
	        appRole = new com.probiz.estore.common.model.system.AppRole(aValue);
	        appRole.setVersion(Integer.valueOf(0));//set a version to cheat hibernate only
	    }
		this.getAppResourceRolePK().setRoleId(appRole.getId());
	}	

	/**
	 * 	 * @return Integer
     * @hibernate.id column="resourceId" type="java.lang.Integer" generator-class="native"
	 */
	public Integer getResourceId() {
		return this.getAppResourceRolePK().getResourceId();
	}
	
	/**
	 * Set the resourceId
	 */	
	public void setResourceId(Integer aValue) {
	    if (aValue==null) {
	    	appResource = null;
	    } else {
	        appResource = new com.probiz.estore.common.model.system.AppResource(aValue);
	        appResource.setVersion(Integer.valueOf(0));//set a version to cheat hibernate only
	    }
		this.getAppResourceRolePK().setResourceId(appResource.getId());
	}	

	/**
	 * @see java.lang.Object#equals(Object)
	 */
	public boolean equals(Object object) {
		if (!(object instanceof AppResourceRoleTbl)) {
			return false;
		}
		AppResourceRoleTbl rhs = (AppResourceRoleTbl) object;
		return new EqualsBuilder()
				.append(this.appResourceRolePK.roleId, rhs.appResourceRolePK.roleId)
				.append(this.appResourceRolePK.resourceId, rhs.appResourceRolePK.resourceId)
				.isEquals();
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return new HashCodeBuilder(-82280557, -700257973)
				.append(this.appResourceRolePK.roleId) 
				.append(this.appResourceRolePK.resourceId) 
				.toHashCode();
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return new ToStringBuilder(this)
				.append("roleId", this.appResourceRolePK.roleId) 
				.append("resourceId", this.appResourceRolePK.resourceId) 
				.toString();
	}

	/**
	 * Return the name of the first key column
	 */
	public String getFirstKeyColumnName() {
		return "roleId";
	}

	/**
	 * Return the primary key as a hashmap
	 */
	public Map getPrimaryKeyMap() {
		
		Map pkMap = new HashMap();
	    pkMap.put("roleId",   this.getRoleId());
	    pkMap.put("resourceId",   this.getResourceId());
		return pkMap;
	}

	/**
	 * Return the primary key String as key value pairs
	 */
	public String getPrimaryKeyString() {
		
		java.lang.StringBuffer pkeyString = new java.lang.StringBuffer("[");
	    pkeyString.append("roleId=");
	    pkeyString.append(this.getRoleId());
		pkeyString.append(",");
	    pkeyString.append("resourceId=");
	    pkeyString.append(this.getResourceId());
	    pkeyString.append("]");
		return pkeyString.toString();
	}
}